<template>
  <!-- 文章详情
      1：封装api
      2:导入与调用
      3：存储与渲染
-->

  <div class="article">
    <van-nav-bar
      title="文章详情"
      left-arrow
      fixed
      placeholder
      @click-left="$router.push('/home')"
    ></van-nav-bar>

    <div class="content">
      <h3 class="title">{{ info.title }}</h3>
      <div class="info">
        <img class="avatar" :src="info.aut_photo" alt="" />
        <div class="txt">
          <div class="name">{{ info.aut_name }}</div>
          <!-- 过滤器：
                  特点：不能用this,只能用于v-bind与{{  }}
                  作用：字符加工
                  到了vue3没有filter

                  vuex==>pinia

        -->
          <div class="time">{{ info.pubdate | formatDate }}</div>
        </div>
        <van-button type="info" round>+ 关注</van-button>
      </div>
      <div class="main" v-html="info.content"></div>
      <van-divider>end</van-divider>
      <div class="btn">
        <van-button class="btn1" icon="good-job-o" plain type="primary" round>
          点赞
        </van-button>
        <van-button icon="delete-o" plain type="danger" round>
          不喜欢
        </van-button>
      </div>
    </div>
    <!-- 评论组件 -->
    <ArticleComment></ArticleComment>
    <!-- 到底部 -->
    <div class="to-bottom" @click="toBottom">到底部</div>
  </div>
</template>
<script>
import { articlesInfo } from '@/api/article'
import ArticleComment from './components/ArticleComment'
export default {
  components: {
    ArticleComment
  },
  data () {
    return {
      info: ''
    }
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const res = await articlesInfo(this.$route.query.id)
      this.info = res.data
      console.log('详情', res)
    },
    toBottom () {
      window.scrollTo(0, 999999999888)
    }
  }
}
</script>
<style lang="less" scoped>
.content {
  padding: 0 10px;
  .title {
    font-size: 20px;
    margin: 15px 0;
  }
  .info {
    display: flex;
    align-items: center;
    .avatar {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      object-fit: cover;
    }
    .txt {
      flex: 1;
      margin: 0 10px;
      .time {
        color: #ccc;
      }
    }
  }
  .btn {
    text-align: center;
    .btn1 {
      margin-right: 20px;
    }
    .van-button {
      width: 120px;
    }
  }
  .main {
    width: 100%;
    overflow: hidden;
    margin-top: 15px;
  }

  ::v-deep pre {
    background-color: #000;
    overflow: auto;
    color: #fff;
    span {
      color: #fff !important;
    }
  }
}
.to-bottom {
  position: fixed;
  right: 20px;
  bottom: 80px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.5);
  text-align: center;
  line-height: 70px;
  color: red;
}
</style>
